

//开始时间
var stadubiao = "";
//结束时间
var endtubiao = "";
//导航
var siteN = "";
//场所中文名称
var siteTypeName = "";
//选择时间的中文名称
var timeModleName = "";

var winWidth = 0;
var numNum = 0;
function getWinWidth(){
	winWidth = $(window).width();
	numNum = parseInt(winWidth / 1600 * 15);
	$(".subbus").each(function() {
		var str = $.trim($(this).html());
		$(this).html(sub(str, numNum));
	});
}

//初始化加载折线图和表格
$(document).ready(function () {
	
	getIndexOrder();
	var width = $("#changsuoleixin").width()
	$("#divpaiming_"+200).css("width",width);
 	$("#divpaiming_"+300).css("width",width);
	$("#divpaiming_"+400).css("width",width);
	$("#divpaiming_"+500).css("width",width);
	$("#divpaiming_"+600).css("width",width);
	$("#divpaiming_"+700).css("width",width);
	initDateObj();
	
	panelId = $("#titles").val();
	if(panelId=="总裁看板"||panelId=="全局分析"){
		$("#todayWeather").hide();
		$("#lastDayWeather").hide();
		$("#lastWeekWeather").hide();
		$(".weatherimg").hide();
	}
	if(panelId=="全局分析"){//解决进入首页加载过慢
		loadJinriZhibiao();	
	}
	
})

var loadingstat = "";
function loadJinriZhibiao(){
	    var siteId= $("#siteKey").val();
		var judgeAll = $("#judgeAll").val();
		showLoading();
		loadingstat = "1"
		$.ajax({
			type : "GET",
	   		contentType:"application/json",
	   		dataType : 'json',
			url: "getTodayTarget",
			data: {siteId: siteId,judgeAll :judgeAll },
			async: true,
			success: function (result) {
				loadingstat = "0";
				hideLoading();
				$("#todayTarget").html(result.result);
				
			},
			error : function(mm, a, b, c, d, e) {
					hideLoading();
					alert("服务器好像开小差了，刷新一下试试吧！");
				}
		})
	
}

var arrpaihang = new Array();
function getRankInfo(lx,Object){

	$(Object).toggleClass("lxxzselected");
	$("#zhibiaopaihangtable td").each(function(){
			var zhibiaopaihang_0 = $(this).attr("id");
			var index = (zhibiaopaihang_0.split("_"))[1];
			if($(this).hasClass("lxxzselected")){
				if(!containsStr(arrpaihang,index)){
					arrpaihang.push(index);	
				}
			}else{
				arrpaihang.remove(index);
			}
		 })
		var rankingType = $("#rankingType").val();
		if (rankingType == "200") {
			array200 = arrpaihang
		}else if(rankingType=="300"){
			array300 =arrpaihang;
		}else if(rankingType=="400"){
			array400 =arrpaihang;
		}else if(rankingType=="500"){
			array500 =arrpaihang;
		}else if(rankingType=="600"){
			array600 =arrpaihang;
		}else if(rankingType=="700"){
			array700 =arrpaihang;
		}
	
	if(arrpaihang.length==0){
		/**
		 * 如果为空设置为第一个有权限的指标
		indexid = $("#zhibiaopaihangtable>tbody>tr").children("td").first().attr("id");
		index = indexid.split("_");
		index = index[1];
		$("#rankingIndex").val(index);
		 */
		//如果为空设置为空
		$("#rankingIndex").val("");
	}else{
		var str = arrpaihang.join();
		$("#rankingIndex").val(str);
	}
	loadlevelRank();
}

//改变场所显示对应场所的排行榜
function changeGC(val){
	arrpaihang = new Array();//切换广场清空已选指标
	$("#divpaiming_200").css("display",'none');
	$("#divpaiming_300").css("display",'none');
	$("#divpaiming_400").css("display",'none');
	$("#divpaiming_500").css("display",'none');
	$("#divpaiming_600").css("display",'none');
	$("#divpaiming_700").css("display",'none');	
 	var option = $(val).val()
 	$("#rankingType").val(option);
 	$("#divpaiming_"+option).css("display","");
	setpaihangIndex(option);
	
	var array = new Array();
	if(option=="200"){array = array200;
	}else if(option=="300"){array = array300;
	}else if(option=="400"){array = array400;
	}else if(option=="500"){array = array500;
	}else if(option=="600"){array = array600;
	}else if(option=="700"){array = array700;}
	if(array.length==0){
		indexid = $("#zhibiaopaihangtable>tbody>tr").children("td").first().attr("id");
		index = indexid.split("_");
		index = index[1];
		$("#rankingIndex").val(index);
		arrpaihang.push(index);
		setpaihangIndexcss(index);
	}else{
		arrpaihang = array;
		for(var i = 0;i<arrpaihang.length;i++){
		$("#zhibiaopaihang_"+arrpaihang[i]).addClass("lxxzselected");
	}
		var str = array.join();
		$("#rankingIndex").val(str);
	}
	loadlevelRank();
}

var rankingData200 = null;
var rankingData300 = null;
var rankingData400 = null;
var rankingData500 = null;
var rankingData600 = null;
var rankingData700 = null;

function saveRankDate(siteType,data){
	
	var indexNames = new Array();
		indexNames.push("innum");
		indexNames.push("jkl");
		indexNames.push("posStaff");
		indexNames.push("pos");
		indexNames.push("rateBags");
		indexNames.push("posInnum");
		indexNames.push("posArea");
		indexNames.push("customerNum");
		indexNames.push("avgWanderTime");
		indexNames.push("newCustomerNum");
		indexNames.push("oldCustomer");
		indexNames.push("newCustomerPro");
		indexNames.push("oldCustomerPro");
		indexNames.push("inStoreRates");
		indexNames.push("returnStoreRates");
		indexNames.push("lossUserNum");
		indexNames.push("lossRates");
		indexNames.push("backUserNum");
		indexNames.push("backRates");
		indexNames.push("memNum");
		indexNames.push("memNumPro");
		indexNames.push("retentionavg");
		indexNames.push("retentionNum");
		indexNames.push("outnum");
		indexNames.push("activeUserNum");
		indexNames.push("activeRates");
		indexNames.push("silenceUserNum");
		indexNames.push("silenceRates");
		indexNames.push("stayUserNum");
		indexNames.push("stayRates");
		indexNames.push("interNum");
		indexNames.push("newInterNum");
		indexNames.push("interAvgDuration");
		indexNames.push("interAvgCount");
		indexNames.push("connectRates");
		indexNames.push("conUserNum");
		indexNames.push("newAddUserNum");
		indexNames.push("firstArrNum");
		indexNames.push("firstArrRates");
		indexNames.push("wifiOpenRate");
		indexNames.push("hisUserNum");
		indexNames.push("inCount");
		indexNames.push("wanderDepth");
		indexNames.push("memTotalNum");
		indexNames.push("serviceAbility");
		indexNames.push("posnum");
		indexNames.push("avgActDayNum");
	var data = changeStringTodouble(data,indexNames);
	
	if(siteType =="200"){
		rankingData200 = data;
	}else if(siteType =="300"){
		rankingData300 = data;
	}else if(siteType =="400"){
		rankingData400 = data;
	}else if(siteType =="500"){
		rankingData500 = data;
	}else if(siteType =="600"){
		rankingData600 = data;
	}else if(siteType =="700"){
		rankingData700 = data;
	}
}



function getRankDate(siteType){

	if(siteType =="200"){
		return rankingData200;
	}else if(siteType =="300"){
		return rankingData300;
	}else if(siteType =="400"){
		return rankingData400;
	}else if(siteType =="500"){
		return rankingData500;
	}else if(siteType =="600"){
		return rankingData600;
	}else if(siteType =="700"){
		return rankingData700;
	}
}

//加载排行榜
function loadPaiHang(siteId,type) {
	$("#changsuoleixin").children().each(function () {
        $(this).hide();
	})
	var from = $('#startDate').val();
	var to = $('#endDate').val();
	var from2 = "";
	var to2 = "";
	if ($("#timecompare").html() == "取消对比") {
	from2 = $('#startCompareDate').val();
	to2 = $('#endCompareDate').val();
	}
	var span = $("#txtspan").val();
	var orderBy =  $("#orderBy").val();
	$.ajax({
		url: "getGlobalRanking",
		data: {siteId: siteId, type: type , from: from, to: to,from2:from2,to2:to2,span:span,orderBy:orderBy},
		async: true,
		success: function (result) {
			var result = result.result;
			var changsuoleix = new Array();
			for (var i = 0;i<result.length;i++){
				var siteType = result[i].siteType;//场所类型
				changsuoleix.push(siteType);
				var data = result[i].data;//数据
				saveRankDate(siteType,data);
			}
			if(changsuoleix.length == 0){
				var str = "<div class='em100 whitediv' id='zhanwushuju'><div class='em25'></div><div class='backyellow'>&nbsp;&nbsp;该场所下面没有需要排行的场所</div></div>"
				$("#divph .whitediv").children().hide();
				$("#divph .whitediv").html(str);
			}else{
				removeSelectOption(changsuoleix);
				var index = "";
				if(containstr(changsuoleix,"700")){
					index = "700";
					$('#select_changsuo').val(700);
				}else{
					var index =$('#select_changsuo option:selected') .val();// 选中索引
				}
				
				var changsuo ="";
				if(index ==""||index == null){
					changsuo = $("#select_changsuo").children().first().attr("value");
					$("#rankingType").val(changsuo);
				}else {
					changsuo = index;
					$("#rankingType").val(changsuo)
				}
				loadfirstranking(changsuo,type);
			}
		},
		error : function(mm, a, b, c, d, e) {
				hideLoading();
				alert("服务器好像开小差了，刷新一下试试吧！");
			}
	});
}

/**
 * 加载改场所的数据
 * @param changsuo
 * @return
 */
function loadfirstranking(changsuo,type){
	$("#divpaiming_"+changsuo).css("display","");

	/**
	 * 加载排行榜时候，取折线图的指标，如果折线图指标在，该场所指标权限里面，则加载折线图指标
	 * 否则，取第一个指标
	 */
	var hasPowerIndex = getSiteOfTimeIndex(changsuo);
	var firstType = "";
	if(containstr(hasPowerIndex,type)){
		firstType = type;
	}else{
		firstType = hasPowerIndex[0];
	}
	//初始化指标结束
	setpaihangIndex(changsuo,firstType);
	
	
	if(firstType !=null){
		arrpaihang = new Array();//清空
		arrpaihang.push(firstType);//插入初始化时第一个指标
		$("#rankingIndex").val(firstType);
		setpaihangIndexcss(firstType);
		var data= getRankDate(changsuo);
		parseDate(changsuo,data);
	}
}
function getsiteTypeChinaName(siteType){
	var siteTypeName = "";
	switch (parseInt(siteType)) {
	case 200:
		siteTypeName = "地区";
		break;
	case 300:
		siteTypeName = "广场";
		break;
	case 400:
		siteTypeName = "区域";
		break;
	case 500:
		siteTypeName = "楼层";
		break;
	case 600:
		siteTypeName = "店铺";
		break;
	case 700:
		siteTypeName = "通道";
		break;
	default:
		break;
	}
	return 	siteTypeName;
}
function parseDate(siteType,data1){
	var orderBy = $("#orderBy").val();
	var rankingIndex = $("#rankingIndex").val();
	var parseDate = orderByType(rankingIndex,data1,orderBy);
	var rankingIndex = rankingIndex.split(",");
	var timeModel = $("#timeModel").val();
	/*
	指标说明选的指标的名称
	*/
	var indexAndIndexName = "";
	for (var i=0; i<rankingIndex.length ; i++) {
		var index = rankingIndex[i];
		indexAndIndexName = indexAndIndexName + array[parseInt(index)]+"("+arraydanwei[parseInt(index)]+")"+"&"
	}
	indexAndIndexName = indexAndIndexName.substring(0,indexAndIndexName.length-1);
	var titNamepaihang = "";
	if(timeModel =="week"){
		 titNamepaihang = "数据说明："+getsiteTypeChinaName(siteType)+timeModleName+"指标排行"+"<br/>"
					+"时间范围："+getTiptollmon(stadubiao)+"~"+(getTiptollsun(endtubiao)==null?'':"~"+getTiptollsun(endtubiao))+"<br/>"
					+"场所名称："+siteN+"<br/>"
					+"指标名称："+indexAndIndexName;
		
	}else{
		 titNamepaihang = "数据说明："+getsiteTypeChinaName(siteType)+timeModleName+"指标排行"+"<br/>"
					+"时间范围："+stadubiao+(endtubiao==null?'':"~"+endtubiao)+"<br/>"
					+"场所名称："+siteN+"<br/>"
					+"指标名称："+indexAndIndexName;
		
	}
	$("#paihangshujushuoming").html(titNamepaihang);
	var zlable = new Array();
	var zlable1 = new Array();
	var zdataPer = new Array();
	var zdata = new Array();
	if(orderBy=="1"){//1升序
		for(var rank = 0; rank< rankingIndex.length; rank++){
			var index = rankingIndex[rank];
			var indexName = getOrderField(index);
			var dataPer = new Array();
			var data = new Array();
			var lable = new Array();
			var lable1 = new Array();
			var max = getFildeMaxValue(parseDate,indexName);
			for(var i = 0; i < parseDate.length; i++){
				var datei = getObjectVlue(parseDate[i],indexName);
				data.push(datei);
				lable.push(parseDate[i].sitename);
				lable1.push(parseInt(i)+1);
				var dataPeri = 0;
				if(max==""||max=="0"){
					dataPeri = 0;
				}else{
					dataPeri = parseInt(datei)/parseInt(max)*100*7/10;
				}
				dataPer.push(dataPeri);
				
			}
			zlable = lable;
			zlable1 = lable1;
			zdataPer.push(dataPer);
			zdata.push(data);
		}
	}else{//0降序
		for(var rank = 0; rank< rankingIndex.length; rank++){
			var index = rankingIndex[rank];
			var indexName = getOrderField(index);
			var dataPer = new Array();
			var data = new Array();
			var lable = new Array();
			var lable1 = new Array();
			var max =  getFildeMaxValue(parseDate,indexName);
			for(var i = 0; i < parseDate.length; i++){
				var datei = getObjectVlue(parseDate[i],indexName);
				data.push(datei);
				lable.push(parseDate[i].sitename);
				lable1.push(parseInt(i)+1);
				var dataPeri = 0;
				if(max==""||max=="0"){
					dataPeri = 0;
				}else{
					dataPeri = parseInt(datei)/parseInt(max)*100*7/10;
				}
				dataPer.push(dataPeri);
				
			}
			zlable = lable;
			zlable1 = lable1;
			zdataPer.push(dataPer);
			zdata.push(data);
		}
		lable1.reverse();
	}
	loadPaihangbang(zdata,zlable,siteType,zdataPer,zlable1,rankingIndex);
}


function orderByType(type,data,order){
	var order = order;//0降序；1升序
	var index ="";
	var data = data;
	if(type != ""){
		index = (type.split(","))[0];
	}
	indexName = getOrderField(index);
	if(order =="1"){//升序
		data.sort(compare1(indexName,"sitename"));
		
	}else{//降序
		data.sort(compare1(indexName,"sitename"));
		data.reverse();
	}
	return data;
}

/**
 * 定义一个比较器 
 * 使用方法
 * data.sort(compare1("name")); 
 * alert(data[0].name);//jiang
 * @param propertyName
 * @return
 */
function compare1(propertyName,name) {
	return function (object1, object2) {
		var value1 = object1[propertyName];
		var value2 = object2[propertyName];
		var name1 = object1[name];
		var name2 = object2[name];
		
		if (value2 < value1) {
			return -1;
		} 
		else if (value2 > value1) {
			return 1;
		}else if(value2 == value1){
			if (name2 < name1) {
			return -1;
			} 
			else if (name2 > name1) {
				return 1;
			}else {
				return 0;
			}
		}else {
			return 0;
		}
	}
}

//导出Excle
function outCSV() {
	var fileName = $("#biaogeshuoming").html();
	var type = $("#hdtype").val();
	var from = $('#startDate').val();
	var to = $('#endDate').val();
	var from2 = "";
	var to2 = "";
	var siteId= $("#siteKey").val();
	var tubiao = "tubiao1";
	var span = $("#txtspan").val();
	if ($("#timecompare").html() == "取消对比") {
		from = $('#startDate').val();
		to = $('#endDate').val();
		from2 = $('#startCompareDate').val();
		to2 = $('#endCompareDate').val();
	}
//	 { from: from, to: to, from2: from2, to2: to2, type: type, span: span, siteId: siteId },
    location.href = "getGlobalExportExcle?from="+from+"&to="+to+"&from2="+from2+"&to2="+to2+"&type="+type+"&span="+span+"&siteId="+siteId+"&fileName="+fileName;
}

 var dateO ;
 var dateO1 ;
//初始化时间段时间控件
function initDateObj() {
	var endDate=new Date();//当前时间
	endDate=endDate.getFullYear()+"-"+(endDate.getMonth()+1)+"-"+endDate.getDate();
	var startDate=(new Date());
	startDate.setDate(startDate.getDate()-30);//前一个月时间
	startDate=startDate.getFullYear()+"-"+(startDate.getMonth()+1)+"-"+startDate.getDate();

	var startMonth=new Date();
	startMonth.setDate(startMonth.getDate()-90);
	startMonth=startMonth.getFullYear()+"-"+(startMonth.getMonth()+1)+"-"+startMonth.getDate();
	
	var startYear=new Date();
	startYear.setFullYear(startYear.getFullYear()-3);
	startYear=startYear.getFullYear()+"-"+(startYear.getMonth()+1)+"-"+startYear.getDate();
	
    var dateObj = {
        theme: 'ta', // 日期选择器TA主题
        autoCommit: false, //自动提交，完成日期初始化，以及图表的展示拉取
        isTodayValid: true,
        startDate: startDate,
        endDate: endDate,
        needCompare: true,
        startCompareDate: '',
        endCompareDate: '',
        singleCompare: false,
        defaultText: ' 至 ',
        autoSubmit: false,
        shortOpr: false,
        target: 'datePicker',
        calendars: 2,
        inputTrigger: 'input_trigger',
        compareCheckboxId: false,
		showcheckbox: false,
        success: function (obj) {
            if (($("#txtspan").val().split("_"))[1] == "0" || $("#needCompare").val() == "1")//处于如期选择框时
            {
                loadChart($("#hdtype").val());
            }
        }
    };
   dateO = new pickerDateRange("date", dateObj);

}

//日时间控件
function hourDateObj(){
	$("#shijianduibi").children().remove();
	var datediv = "<div id='div_date' class='nocheckoption' style='cursor:pointer;'  onclick=getspan('day_0')>"+
       "<span id='date' onclick=getspan('day_0')>2015-5-1</span>"+
   		"</div>"
	$("#shijianduibi").html(datediv);
	var endDate=new Date();//当前时间
	endDate=endDate.getFullYear()+"-"+(endDate.getMonth()+1)+"-"+endDate.getDate();
	var dateObj1 = {
	    theme: 'ta', // 日期选择器TA主题
	    autoCommit: false, //自动提交，完成日期初始化，以及图表的展示拉取
	    isTodayValid: true,
	    startDate: endDate,
	    endDate: endDate,
	    needCompare: true,
	    startCompareDate: '',
	    endCompareDate: '',
	    singleCompare: false,
	    defaultText: ' 至 ',
	    autoSubmit: false,
	    shortOpr: true,
	    target: 'datePicker',
	    calendars: 2,
	    isSingleDay: true,
		singleCompare: false,
//		dayRangeMax: 1,
	    inputTrigger: 'input_trigger',
	    compareCheckboxId: false,
	    success: function (obj) {
	        if (($("#txtspan").val().split("_"))[1] == "0" || $("#needCompare").val() == "1")//处于如期选择框时
	        {
	            loadChart($("#hdtype").val());
	        }
	    }
	};
   new pickerDateRange("date", dateObj1);
}
//日周月年控件
function rizhouDateObj(){
		$("#shijianduibi").children().remove();
	var datediv = "<div id='div_date' class='nocheckoption' style='cursor:pointer;'  onclick=getspan('day_0')>"+
       "<span id='date' onclick=getspan('day_0')>2015-5-1</span>"+
   		"</div>"
	$("#shijianduibi").html(datediv);
		var endDate=new Date();//当前时间
		endDate=endDate.getFullYear()+"-"+(endDate.getMonth()+1)+"-"+endDate.getDate();
		var startDate=(new Date());
		startDate.setDate(startDate.getDate()-30);//前一个月时间
		startDate=startDate.getFullYear()+"-"+(startDate.getMonth()+1)+"-"+startDate.getDate();
	
		var startMonth=new Date();
		startMonth.setDate(startMonth.getDate()-90);
		startMonth=startMonth.getFullYear()+"-"+(startMonth.getMonth()+1)+"-"+startMonth.getDate();
		
		var startYear=new Date();
		startYear.setFullYear(startYear.getFullYear()-3);
		startYear=startYear.getFullYear()+"-"+(startYear.getMonth()+1)+"-"+startYear.getDate();
	   var dateObj = {
        theme: 'ta', // 日期选择器TA主题
        autoCommit: false, //自动提交，完成日期初始化，以及图表的展示拉取
        isTodayValid: true,
        startDate: startDate,
        endDate: endDate,
        needCompare: true,
        startCompareDate: '',
        endCompareDate: '',
        singleCompare: false,
        defaultText: ' 至 ',
        autoSubmit: false,
        shortOpr: false,
        target: 'datePicker',
        calendars: 2,
        inputTrigger: 'input_trigger',
        compareCheckboxId: false,
        success: function (obj) {
            if (($("#txtspan").val().split("_"))[1] == "0" || $("#needCompare").val() == "1")//处于如期选择框时
            {
                loadChart($("#hdtype").val());
            }
        }
    };
  new pickerDateRange("date", dateObj);
}
    
function showAllRanking(type) {
    $("#shuju_site" + type + " .shujuhang").show();
    $("#divshowallRanking" + type).hide();
}

//加载折线图表取XY轴
function  getXY(timeType_table,result,type) {
	var xsisRe="";
	var dataRe="";
		for(var i=0;i<result.length;i++){
			if(timeType_table=="day"||timeType_table=="hour"){
				xsisRe=xsisRe + result[i].datatime+",";
			}else if(timeType_table=="week"){
				xsisRe=xsisRe + result[i].year+"."+result[i].week +",";
			}else if(timeType_table=="month"){
				xsisRe=xsisRe + result[i].year+"."+result[i].month +",";
			}else {
				xsisRe=xsisRe + result[i].year +",";
			}
			indexNamefiled = getOrderField(type);
			 dataRe = dataRe+((getObjectVlue(result[i],indexNamefiled))==null?0:(getObjectVlue(result[i],indexNamefiled)))+",";
			
		}
	xsisRe=xsisRe.substring(0,xsisRe.length-1);
	dataRe=dataRe.substring(0,dataRe.length-1);
	var result =new Array();
	result.push(xsisRe);
	result.push(dataRe);
	return result
}

function  getCompearXY(timeType_table,result,compareResult,type){

	var xsisRe="";
	var dataRe="";
	var comparedataRe="";
	
	var resultsize = result.length;
	var compareResultsize = compareResult.length;
	var xsissize = 0;
	if(resultsize>=compareResultsize){
		xsissize = resultsize;
	}else{
		xsissize = compareResultsize;
	}
	var resultTime = new Array();
	var resultCompTime = new Array();
	
		for(var i=0;i<xsissize;i++){
			if(timeType_table=="day"||timeType_table=="hour"){
				if(i<resultsize&&i<compareResultsize){
					xsisRe=xsisRe + result[i].datatime+"\n";
					xsisRe=xsisRe + compareResult[i].datatime+",";
					resultTime.push(result[i].datatime);
					resultCompTime.push(compareResult[i].datatime);
				}else if(i<resultsize){
					xsisRe=xsisRe + result[i].datatime+",";
					resultTime.push(result[i].datatime);
				}else if(i<compareResultsize){
					xsisRe=xsisRe + "\n"+compareResult[i].datatime+",";
					resultCompTime.push(compareResult[i].datatime);
				}
			}else if(timeType_table=="week"){
				if(i<resultsize&&i<compareResultsize){
					xsisRe=xsisRe + result[i].year+"."+result[i].week +"\n";
					xsisRe=xsisRe + compareResult[i].year+"."+compareResult[i].week +",";
					resultTime.push(result[i].year+"."+result[i].week);
					resultCompTime.push(compareResult[i].year+"."+compareResult[i].week);
				}else if(i<resultsize){
					xsisRe=xsisRe + result[i].year+"."+result[i].week +",";
					resultTime.push(result[i].year+"."+result[i].week);
				}else if(i<compareResultsize){
					xsisRe=xsisRe + "\n"+compareResult[i].year+"."+compareResult[i].week +",";
					resultCompTime.push(compareResult[i].year+"."+compareResult[i].week);
				}
			}else if(timeType_table=="month"){
				if(i<resultsize&&i<compareResultsize){
					xsisRe=xsisRe + result[i].year+"."+result[i].month +"\n";
					xsisRe=xsisRe + compareResult[i].year+"."+compareResult[i].month +",";
					resultTime.push(result[i].year+"."+result[i].month);
					resultCompTime.push(compareResult[i].year+"."+compareResult[i].month);
				}else if(i<resultsize){
					xsisRe=xsisRe + result[i].year+"."+result[i].month +",";
					resultTime.push(result[i].year+"."+result[i].month);
				}else if(i<compareResultsize){
					xsisRe=xsisRe + "\n"+compareResult[i].year+"."+compareResult[i].month +",";
					resultCompTime.push(compareResult[i].year+"."+compareResult[i].month);
				}
			}else{
				if(i<resultsize&&i<compareResultsize){
					xsisRe=xsisRe + result[i].year +"\n";
					xsisRe=xsisRe + compareResult[i].year +",";
					resultTime.push(result[i].year);
					resultCompTime.push(compareResult[i].year);
				}else if(i<resultsize){
					xsisRe=xsisRe + result[i].year +",";
					resultTime.push(result[i].year);
				}else if(i<compareResultsize){
					xsisRe=xsisRe + "\n"+compareResult[i].year +",";
					resultCompTime.push(compareResult[i].year);
				}
			}
			 indexNamefiled = getOrderField(type);
			 if(i<resultsize){
				 dataRe = dataRe+((getObjectVlue(result[i],indexNamefiled))==null?0:(getObjectVlue(result[i],indexNamefiled)))+",";
			 }
			 if(i<compareResultsize){
				 comparedataRe=comparedataRe + ((getObjectVlue(compareResult[i],indexNamefiled))==null?0:(getObjectVlue(compareResult[i],indexNamefiled)))+",";
			 }
		}
		
	xsisRe=xsisRe.substring(0,xsisRe.length-1);
	dataRe=dataRe.substring(0,dataRe.length-1);
	comparedataRe=comparedataRe.substring(0,comparedataRe.length-1);
	var result =new Array();
	result.push(xsisRe);
	result.push(dataRe);
	result.push(comparedataRe);
	result.push(resultTime.join());
	result.push(resultCompTime.join());
	return result
}

//加载折线图表
 function loadChart(type) {
 	 
	 showLoading();
	 //指标显示底色
	 zhibiaoCss(type)
	 //获取指标名称
     var indexname = array[parseInt(type)];
	 //获取指标单位
	 var zhibiaodanwei = arraydanwei[parseInt(type)];
     var data = [];
     var xsis = [];
     var from = $('#startDate').val();
     var to = $('#endDate').val();
     var from2 = "";
     var to2 = "";
     var siteId= $("#siteKey").val();
     var tubiao = "tubiao1";
     var spancss = $("#txtspan").val();
     shijianCss(spancss);
     /**如果spancss为day_0需要判断timeModel的值，如果是day则设置为day_0；
      如果是week则设置为week_0；如果是month则设置为month_0；如果是year
      则设置为year_0；*/
     if($("#timeModel").val()=="hour"&&spancss=="day_0"){
	 	$("#txtspan").val("hour_0");
	 }else if($("#timeModel").val()=="day"&&spancss=="day_0"){
     	$("#txtspan").val("day_0");
 	 }else if($("#timeModel").val()=="week"&&spancss=="day_0"){
 		 $("#txtspan").val("week_0");
 	 }else if($("#timeModel").val()=="month"&&spancss=="day_0"){
 		 $("#txtspan").val("month_0");
 	 }else if($("#timeModel").val()=="year"&&spancss=="day_0"){
 		 $("#txtspan").val("year_0");
 	 }
     var span = $("#txtspan").val();
     if ($("#timecompare").html() == "取消对比") {
         from = $('#startDate').val();
         to = $('#endDate').val();
         from2 = $('#startCompareDate').val();
         to2 = $('#endCompareDate').val();
         tubiao = "tubiao2";
     }
     var myChart = echarts.init(document.getElementById(tubiao));
	 
   	$.ajax( {
   		type : "GET",
   		contentType:"application/json",
   		dataType : 'json',
   		url: "getGlobalAnalysis",
   		data: { from: from, to: to, from2: from2, to2: to2, type: type, span: span, siteId: siteId },
   		async: true,
   		success : function(ret) {
			$(".contrast").hide();
   			//下面表情的位置
   			var titleOffens = "";
   			var dataZoomY = "";;
   			var toolboxX = "";
   			siteN=ret.siteN;
   			stadubiao=ret.stadubiao;
   			endtubiao=ret.endtubiao;
   			siteName = ret.siteName;
			siteTypeName = ret.siteTypeName //场所中文名称
   			var compstadubiao=ret.compstadubiao;
   			var compendtubiao=ret.compendtubiao;
   			var timeType_table = ret.timeType_table;//返回的日周月年
   			var  result = ret.result;//返回数据集
   			var  compareResult = ret.compareResult;//返回比较数据集
   			var xsisRe="";//X轴
   			var dataRe="";//数据线
   			var comparedataRe="";//比较数据线
   			var titName="";//表题
   			var resultTime ="";//原时间
   			var resultCompTime ="";//对比时间
			if(timeType_table == "hour"){
				timeModleName = "时";
			}else if(timeType_table == "day"){
   				timeModleName = "日";
   			}else if(timeType_table == "week"){
   				timeModleName = "周";
   			}else if(timeType_table == "month"){
   				timeModleName = "月";
   			}else if(timeType_table == "year"){
   				timeModleName = "年";
   			}
   			/*
			详细数据拼接指标及单位
			var indexListName = "";
			$("#zhibiaotable tr").each(function(){
				var  indexListName_id =  $(this).children("td").attr("id");
				var indexListName_index = indexListName_id.split("_")[1];
				indexListName   = indexListName+ array[parseInt(indexListName_index)]+"（"+arraydanwei[parseInt(indexListName_index)]+"）"+"&"
			});
			indexListName = indexListName.substring(0,indexListName.length-1);
			*/
			/*
			详细数据拼接指标及单位
			*/
			var indexListName = "";
			var indexListDetils = $("#indexListDetil").val();
			
			
			if(indexListDetils != null&&indexListDetils != ""){
				indexListDetils = eval(indexListDetils);
				
				//根据权限去除指标-indexDay时间，tableHead后台table的表头
//				var tableHead = [0,1,2,3,4,5,6,21,22,23,7,9,10,11,12,14,19,24,26,30,31,32];
  				var tableHead = new Array();
				for(var i =0;i<47;i++){
					tableHead.push(i);
				}
				var indexDay = dateindexPowerList[getTimeIndexList()];
				indexDay = eval(indexDay);
				var name = new Array();
				for (var i=0; i<indexListDetils.length; i++) {
					if(containstr(tableHead,indexListDetils[i])){
						if(containstr(indexDay,indexListDetils[i])){
							name.push(indexListDetils[i])
						}
					}
				};
				indexListDetils = name;
				for (var i=0; i<indexListDetils.length; i++) {
				var indexListName_index = indexListDetils[i];
				indexListName   = indexListName+ array[parseInt(indexListName_index)]+"（"+arraydanwei[parseInt(indexListName_index)]+"）"+"&"
				};
				indexListName = indexListName.substring(0,indexListName.length-1);
			}
			
   			//如果不是时间比较
   			if($("#needCompare").val() == "0"){
   				var width = $("#tubiao1").width();
   				var height = $("#tubiao1").height();
   				titleOffens = width*7.6/100;
   				dataZoomY = height*(1-19/100);
   				toolboxX = width*80/100;
   				if(timeType_table == "week"){
					titContext="数据说明："+siteTypeName+timeModleName+"指标趋势分析"+"\n"
					+"时间范围："+getTiptollmon(stadubiao)+(endtubiao==null?'':"~"+getTiptollsun(endtubiao))+"\n"
					+"场所名称："+siteN+"\n"
					+"指标名称："+indexname+"（"+zhibiaodanwei+"）";
   				}else{
   					titContext="数据说明："+siteTypeName+timeModleName+"指标趋势分析"+"\n"
					+"时间范围："+stadubiao+(endtubiao==null?'':"~"+endtubiao)+"\n"
					+"场所名称："+siteN+"\n"
					+"指标名称："+indexname+"（"+zhibiaodanwei+"）";
   				}
				var biaogeshuomingContext = "";
				if (timeType_table == "week") {
					biaogeshuomingContext = "数据说明："+siteTypeName+timeModleName+"指标明细"+"<br/>"
					+"时间范围："+getTiptollmon(stadubiao)+(endtubiao==null?'':"~"+getTiptollsun(endtubiao))+"<br/>"
					+"场所名称："+siteN+"<br/>"
					+"指标名称："+indexListName;
				}else{
					biaogeshuomingContext = "数据说明："+siteTypeName+timeModleName+"指标明细"+"<br/>"
					+"时间范围："+stadubiao+(endtubiao==null?'':"~"+endtubiao)+"<br/>"
					+"场所名称："+siteN+"<br/>"
					+"指标名称："+indexListName;
				}
   				$("#biaogeshuoming").html(biaogeshuomingContext);
   				var resultXY=getXY(timeType_table,result,type);
   				xsisRe=resultXY[0];
   				dataRe=resultXY[1];
   			}else{//如果是时间比较
   				var width = $("#tubiao2").width();
   				var height = $("#tubiao2").height();
   				titleOffens = width*7.6/100;
   				dataZoomY = height*(1-19/100);
   				toolboxX = width*80/100;
   				if(timeType_table == "week"){
   					titContext="数据说明："+siteTypeName+timeModleName+"指标趋势分析"+"\n"
					+"时间范围："+getTiptollmon(stadubiao)+(endtubiao==null?'':"~"+getTiptollsun(endtubiao))+"对比"+getTiptollmon(compstadubiao)+(endtubiao==null?'':"~"+getTiptollsun(compendtubiao))+"\n"
					+"场所名称："+siteN+"\n"
					+"指标名称："+indexname+"（"+zhibiaodanwei+"）";
				
				}else{
   					titContext="数据说明："+siteTypeName+timeModleName+"指标趋势分析"+"\n"
					+"时间范围："+stadubiao+(endtubiao==null?'':"~"+endtubiao)+"对比"+compstadubiao+(endtubiao==null?'':"~"+compendtubiao)+"\n"
					+"场所名称："+siteN+"\n"
					+"指标名称："+indexname+"（"+zhibiaodanwei+"）";
				}
				if (timeType_table == "week") {
					var biaogeshuomingContext = "数据说明："+siteTypeName+timeModleName+"指标明细"+"<br/>"
					+"时间范围："+getTiptollmon(stadubiao)+(endtubiao==null?'':"~"+getTiptollsun(endtubiao))+"对比"+getTiptollmon(compstadubiao)+(endtubiao==null?'':"~"+getTiptollsun(compendtubiao))+"<br/>"
					+"场所名称："+siteN+"<br/>"
					+"指标名称："+indexListName;
				}else{
					var biaogeshuomingContext = "数据说明："+siteTypeName+timeModleName+"指标明细"+"<br/>"
					+"时间范围："+stadubiao+(endtubiao==null?'':"~"+endtubiao)+"对比"+compstadubiao+(endtubiao==null?'':"~"+compendtubiao)+"<br/>"
					+"场所名称："+siteN+"<br/>"
					+"指标名称："+indexListName;
				}
				
				
   				
				$("#biaogeshuoming").html(biaogeshuomingContext);
				
				var resultXY = getCompearXY(timeType_table,result,compareResult,type)
   				xsisRe=resultXY[0];
   				dataRe=resultXY[1];
   				comparedataRe=resultXY[2];
   				resultTime =resultXY[3];
   				resultCompTime = resultXY[4];
   			}
   			resultTime = resultTime.split(",");
   			resultCompTime = resultCompTime.split(",");
   			xsis = xsisRe.split(","); 
   			
   			/**
   			 * 横坐标只有一个值时显示为柱状图，柱状宽度最大为40
   			 */
   			var lineType = 'line';
   			if(xsis.length ==1){
   				lineType = 'bar';
   			}else{
   				lineType = 'line';
   			}
			//获取当前时间
			var date = new Date;
			var today =  timeFormat(date);
			//保存图片的名称
			var toolboxName = $("#titles").val()+'-趋势分析'+today;
   			var barMaxWidthn = 40;
   			var markLinePrecision = 0;
   			if($("#needCompare").val() == "0"){
   			data = eval("[{name:'"+from+"~"+to+indexname+"',markLine: {precision:markLinePrecision, data: [{type: 'average',name: '平均值'}]},type:lineType,smooth: smoothType,barMaxWidth:barMaxWidthn,itemStyle:{ normal:{color:'#feab41'}},itemStyle:{normal:{label:{show:"+getShow(xsis)+",position:'top'}}},data:[" +dataRe + "]}]");
   			}else{
   				data = eval("[{name:'"+from+"~"+to+indexname+"',markLine: {precision:markLinePrecision,data: [{type: 'average',name: '平均值'}]},type:lineType,smooth: smoothType,barMaxWidth:barMaxWidthn,itemStyle:{ normal:{color:'#feab41'}},itemStyle:{normal:{label:{show:"+getShow(xsis)+",position:'top'}}},data:[" +dataRe + "]},{name:'"+from2+"~"+to2+indexname+"',markLine: {precision:markLinePrecision,data: [{type: 'average',name: '平均值'}]},type:lineType,smooth: smoothType,barMaxWidth:barMaxWidthn,itemStyle:{ normal:{color:'#00BFFF'}},itemStyle:{normal:{label:{show:"+getShow(xsis)+",position:'top'}}},data:[" +comparedataRe + "]}]");	
   			}
   			var  option = {
   			title : {
   		      text: titContext,
   		      y:'bottom',
   		      x:titleOffens,
   		      textStyle:{
   		        fontSize: 12,
   		        color: '#666',
				fontFamily:'微软雅黑, 兰亭细黑, 宋体',
   		        fontWeight:'normal'
   		    	}		
   		    },
   		    dataZoom: {
   		        show: true,
   		        y:dataZoomY 
   		    },
   			tooltip : {
   				trigger: 'axis',
   				backgroundColor: 'rgba(0,0,0,0.7)',
   				position: function(p) {
   					return [p[0] + 10, p[1] - 10];
   				},
   				formatter: function(params, ticket, callback) {
   					//如果不是时间比较
					console.log(params);
					//console.log(resultTime);
					//console.log(resultCompTime);
					var time = "";
					var c = "";
					var time1 = "";
					var c1 = "";
   					if($("#needCompare").val() == "0"){
	   		   			time = params[0][1];
						c = params[0][2];
   		   			}else{
	   					var dataIndex = params[0].dataIndex;
   						time = resultTime[dataIndex];
   						time1 = resultCompTime[dataIndex];
						c = params[0][2];
						c1 = params[1][2];
		   			}
						
//   		   				if(params[1]=="平均值"){
//   		   					time = "平均值";
//   		   				}else{
//	   		   				var seriesIndex = params.seriesIndex;
//		   					var dataIndex = params.dataIndex;
//		   					var time = "";
//		   					if(seriesIndex ==0){
//		   						time = resultTime[dataIndex];
//		   					}else if(seriesIndex ==1){
//		   						time = resultCompTime[dataIndex];
//		   					}
//   		   				}
   		   			
   					var a = siteName;
   					
   					c = addKannma(c);
   					if (c == '') {
   						c = 0;
   					}
					c1 = addKannma(c1);
   					if (c1 == '') {
   						c1 = 0;
   					}
					if($("#needCompare").val() == "0"){
						if(timeType_table == "week"){
	   						return getTiptollTime(time) + '<br/>' + siteName + ' : ' + c;
	   					}else{
	   						return time+'<br/>'+siteName+' : '+c;
	   					}
					}else{
						if(timeType_table == "week"){
	   						return getTiptollTime(time) + '<br/>' + siteName + ' : ' + c +'<br/>'+getTiptollTime(time1) + '<br/>' + siteName + ' : ' + c1;
	   					}else{
	   						return time+'<br/>'+siteName+' : '+c+ '<br/>' +time1+'<br/>'+siteName+' : '+c1;
	   					}
						
					}
   					
   				}
   			},
   			grid:{
   				x:'7.6%',
   				y:'11%',
   				y2:'27%',
   				borderWidth: gridBorderWidth,
				borderColor:'#EEE'
   			},
		    toolbox: {
		        show : true,
		        feature : {
		            mark : {show: true},
		            magicType : {show: true, type: ['line', 'bar']},
		            restore : {show: true},
		            saveAsImage : {
						show: true,
						name: toolboxName 
					}
		        },
		        x:toolboxX
		    },
		    calculable : true,
		    xAxis : [
		        {
		        	name : '日期'+'('+timeModleName+')',
		        	boundaryGap: true,//两端空白策略
		        	allowDecimals :true,//使用小数
		            type : 'category',
		            splitLine: {show: xAxisSplitLine,
					lineStyle:{
							 color: ['#EEE'],
							
						}},//不显示竖线
		            splitArea:{
						show:xAxissplitArea,
						areaStyle:{
								color: [
						        'rgba(250,250,250,0.1)',
						        'rgba(200,200,200,0.1)']
							}
					},
		            data : xsis,
		            axisTick:{
						show:true,
						interval:0
					}
		        }
		    ],
		    yAxis : [
		        {
					axisLabel:{
						formatter: function (value) {
		            		if(value > 10000){
		            			return (value/10000)+'万';
		            		}else{
		            			return value + '';
		            		}
						}
					},
		        	splitLine: {
						show: yAxisSplitLine,
						lineStyle:{
							 color: ['#EEE'],
							
						}},//不显示竖线
		        	splitArea:{
						show:yAxissplitArea,
						areaStyle:{
							color: [
					        'rgba(250,250,250,0.1)',
					        'rgba(200,200,200,0.1)']
						}
					},
		        	name : indexname+'('+zhibiaodanwei+')',
		            type : 'value'
		        }
		    ],
		    series : data
		};
   			//改变窗口大小使图标自适应窗口显示
   			window.onresize = function () {
   				myChart.resize();
   			}
   			//加载折线图
   			myChart.setOption(option);
   			//加载表格
   			loadTable(ret.loadTable);
   			//加载排行榜
   			if($("#needCompare").val() == "0" && $("#changsuoleixin").length > 0){
   				loadPaiHang(siteId,type);
   			}
			if(loadingstat == "0"||loadingstat==""){
				hideLoading();	
			}
   			
   		},
		error : function(mm, a, b, c, d, e) {
				if(loadingstat == "0"||loadingstat==""){
					hideLoading();
				}
				alert("服务器好像开小差了，刷新一下试试吧！");
			}
   	})
	
}
 
 function load(type) {
	    if (type == 0) {
	        var hei = $(document).height();
	        $("#mask4main").attr("style", "height: " + hei + "px; left: 0px; position: absolute; top: 0px; text-align: center; width: 100%; background: none repeat scroll 0% 0% rgb(255, 255, 255); opacity: 0.4; z-index: 98;background:#fff; filter: alpha(opacity=40)");
	    }
	    else {
	        $("#mask4main").attr("style", "display:none");
	    }
	}

 var time1 = null;
 var time2 = null;

 function _startmarquee(lh, speed, delay, st) {

     return function startmarquee() {
         var t;
         var oHeight = $("#listBox").width(); /** div的高度 **/
         var o = document.getElementById("listBox");
         var p = false;

         $('#listBox').animate({ 'scrollLeft': o.scrollLeft + lh }, 100)
     }
 }
 function _startmarquee1(lh, speed, delay, st) {
     return function startmarquee1() {
         var t;
         var oHeight = $("#listBox").width(); /** div的高度 **/
         var o = document.getElementById("listBox");
         var p = false;

         $('#listBox').animate({ 'scrollLeft': o.scrollLeft - lh }, 100)
     }
 } //setTimeout(start, delay)

 function startmarquee1_do(lh, speed, delay, st) {
     if (st == 0) {
         time2 = setInterval(_startmarquee1(lh, speed, delay, st), delay);
     }
     else {
         clearInterval(time2);
     }

 }
 function startmarquee_do(lh, speed, delay, st) {
     if (st == 0) {

         time1 = setInterval(_startmarquee(lh, speed, delay, st), delay);
     }
     else {

         clearInterval(time1);
     }
 }
	
function compare(){

    
    dispDayDivChildren();
    
    $("#shijian_sd").show();
  $("#shijian_compare2").show();
    $("#shijian_compare3").show();
    
    $("#divDay").css("width","0");
    $("#xuanzesj").css("width","37.4em");
    
    
    $("#div_date").css("float","left");
    $("#div_date").css("margin-left","10%");
	$("#div_date").css("margin-right","5%");
	
     if($("#timeModel").val()=="hour"){
	 	$("#div_date").css("margin-left","20%");
		$("#div_date").css("margin-right","13%");
		
 	 }
    
    $("#shijianduibi").css("width","100%");
    $("#shijianduibi").removeClass("div240");
    $("#shijianduibi").addClass("div600");
   
    $("#shijian_compare2").css("font-size","13px");
	$("#shijian_compare2").css("line-height","2");
   

	$("#shijian_compare3").css("width","40%");
    $("#shijian_compare3").css("border-style","none");
    $("#shijian_compare3").css("font-size","13px");
    $("#shijian_compare3").css("color","black");
    $("#shijian_compare3").css("line-height","2");
    $("#shijian_compare3").addClass("lxxzselected");
    $("#compare_trigger").hide();
    $("#timecompare").html("取消对比");
    
    $("#tubiao1").hide();
    $("#tubiao2").show();
    $("#needCompare").val("1");
    $("#divph").css("display","none");
    if($("#timeModel").val()=="hour"){
    	$("#txtspan").val("hour_0");
	 }else if($("#timeModel").val()=="day"){
    	$("#txtspan").val("day_0");
	 }else if($("#timeModel").val()=="week"){
		 $("#txtspan").val("week_0");
	 }else if($("#timeModel").val()=="month"){
		 $("#txtspan").val("month_0");
	 }else{
		 $("#txtspan").val("year_0");
	 }
		$(".contrast").hide();
//    
}

function nocompare(){
	$("#divDay").css("width","23.6%");
	$("#xuanzesj").css("width","15em");
	
	$("#shijianduibi").removeClass("div600");
    $("#shijianduibi").addClass("div240");
	if($("#timeModel").val()=="hour"){
    	$("#txtspan").val("hour_1");
	 }else if($("#timeModel").val()=="day"){
    	$("#txtspan").val("day_7");
	 }else if($("#timeModel").val()=="week"){
		 $("#txtspan").val("week_4");
	 }else if($("#timeModel").val()=="month"){
		 $("#txtspan").val("month_3");
	 }else{
		 $("#txtspan").val("year_3");
	 }
	 	dispDayDivChildren();
   $("#shijian_sd").show();
   $("#shijian_compare2").hide();
   $("#shijian_compare3").hide();
   //$("#shijianduibi").css("width","40%");
   $("#div_date").css("float","none");
   $("#timecompare").html("按时间对比");
   
   $("#tubiao2").hide();
   $("#tubiao1").show();
   
   $("#needCompare").val("0");
   if($("#timeModel").val()=="hour"){
 		 hourDivDisplay();
 	 }else if($("#timeModel").val()=="day"){
 		 dayDivDisplay();
 	 }else if($("#timeModel").val()=="week"){
 		 weekDivDisplay();
 	 }else if($("#timeModel").val()=="month"){
 		 monthDivDisplay();
 	 }else{
 		 yearDivDisplay();
 	 }
   
   $("#divph").css("display","");
   loadChart($("#hdtype").val());
   loadTable();

}

function timecomparefn() {
    if ($("#needCompare").val() == "0") {
    	compare();
    }else {
    	nocompare();
    }
}

function fromsubmit(){
			var  siteKey=$('#siteKey').val();
			$('#selectSitekey').val(siteKey);
			$('#siteSelectForm').submit();
		}
	
function showsitetype(){
	$("#selecttype").toggle();
	if($("#selectsitetypeimg").hasClass("xuanzhuan")){
		$("#selectsitetypeimg").removeClass("xuanzhuan");
	}else{
		$("#selectsitetypeimg").addClass("xuanzhuan");
	}
}
function paihangpaixu(){
	var src=$("#phpaixu").attr("src");
	if(src.indexOf("asc.png")>0){
		$("#phpaixu").attr("src","images/desc.png");
		$("#orderBy").val("1");
	}else{
		$("#phpaixu").attr("src","images/asc.png");
		$("#orderBy").val("0");
	}
	loadlevelRank();
}
/**
 * 切换场所，加载排行榜数据
 * @return
 */
function loadRank(){
	var changsuo = $("#rankingType").val();
	$("#divpaiming_"+changsuo).css("display","");
	setpaihangIndex(changsuo);
	var rankingIndex = $("#rankingIndex").val();
	if(rankingIndex !=""){
		var data= getRankDate(changsuo);
		parseDate(changsuo,data);
	}else{
		$("#divpaiming_"+changsuo).css("display","none");
		$("#paihangshujushuoming").html("");
	}
}
/**
 * 选择指标，点击排序.加载排行榜
 */
function loadlevelRank(){
	var changsuo = $("#rankingType").val();
	$("#divpaiming_"+changsuo).css("display","");
	var rankingIndex = $("#rankingIndex").val();
	if(rankingIndex !=""){
		var data= getRankDate(changsuo);
		parseDate(changsuo,data);
	}else{
		$("#divpaiming_"+changsuo).css("display","none");
		$("#paihangshujushuoming").html("");
	}
}
/**
 * 设置指标颜色
 * @param index
 * @param color
 * @return
 */
function setPhZbColor(index,color){
	$("#zhibiaopaihang_"+index).css("color",color);
	
}
function loadPaihangbang(data1,lable,siteType,zdataPer,lable1,rankingIndex){
	var myChart = echarts.init(document.getElementById("divpaiming_"+siteType));
	var data1 = eval(data1);
	var zdataPer = eval(zdataPer);
	var legendDate = new Array();
	var num =zdataPer[0].length;
	var datatemp = "";
	for(var temp=0;temp<zdataPer.length;temp++){
		var data = data1[temp];
		var dataper= zdataPer[temp]
		var paihaindex = rankingIndex[temp];
		//获取指标名称
	     var paihaIndexname = array[parseInt(paihaindex)];
		 //获取指标单位
		 var paihaZhibiaodanwei = arraydanwei[parseInt(paihaindex)];
		var values = ""; 
		for(var dp = 0;dp <data.length;dp++ ){
			values = values+"{value: "+dataper[dp]+",tooltip : {show : true,backgroundColor: 'rgba(0,0,0,0.7)',position: function(p) {return [p[0] + 10, p[1] - 10];},formatter: '"+paihaIndexname+"("+paihaZhibiaodanwei+"):"+addKannma(data[dp])+"' }},";
		}
		datatemp = datatemp + "{barMaxWidth:20, barGap:'1%',barCategoryGap:10,name:'"+array[rankingIndex[temp]]+"',type:'bar',data: ["+values+"]},";
		legendDate.push(array[rankingIndex[temp]]);
	}
	datatemp = datatemp.substring(0,datatemp.length - 1);
	datatemp = eval("["+datatemp+"]");
	var paihangwidth = $("#changsuoleixin").width();
	var paihangheight = $("#changsuoleixin").height();
	var lable = eval(lable);
	
//	var xAxisMax = maxDate;
	var dataZoomEnd = 0;
	var dataZoomshow = true;//是否显示数据区域，如果小于等于7就不显示
	
	if( parseInt(num)<=7){
		dataZoomshow = false;
		dataZoomEnd=0;
	}else{
		dataZoomEnd =100-(100*7/num);
	}
	dataZoomX = paihangwidth*95.73/100;
	
	if( parseInt(num)<=7){
	var Y = 100- num*(90/7);
	var gridY = Y+'%';
	}else{
		gridY = "10%";
	}
	dataZoomHeight = paihangheight*94.7/100;
//	var myChart = echarts.init(document.getElementById("divpaiming_300"));
	option = {
	    calculable : false,
	    dataZoom : {
//	    	handleColor:'rgba(68,182,234,0.8)',
//	    	fillerColor:'rgba(68,182,234,0.8)',
	      	orient:"horizontal",//horizontal,vertical
	        show : dataZoomshow,
	        realtime : true,
	        showDetail:false,
//	        height: dataZoomHeight,
	        start : dataZoomEnd,
	        end : 100,
	        zoomLock:true,
//	        x:dataZoomX,
	    },
	    tooltip : {
//	    	 trigger: 'item',
	    },
	    legend: {
	    	x: '5.3%',
			y: '0%',
	        data:legendDate
	    },
	    grid: {
			x: '5.3%',
	    	y:'5%',
	    	y2:gridY,
	    	x2: '10%',
			borderWidth: gridBorderWidth,
			borderColor:'#EEE'
		},
	   yAxis : [
	        {
				 splitLine: {show: yAxisSplitLine,
					lineStyle:{
							 color: ['#EEE'],
							
						}},//不显示竖线
		        splitArea:{
					show:yAxissplitArea,
					areaStyle:{
								color: [
						        'rgba(250,250,250,0.1)',
						        'rgba(200,200,200,0.1)']
							}
				},
	            type : 'category',
	            boundaryGap : true,
	        	splitLine:{
	        		show:false
	            },
	          	axisLabel :{
	        		show:true
	            },
	            axisTick:{
        			show:false
	        	},
				axisLine :{
	        		show:false
	        	},
	            data : lable1
	        },
	     {
	            type : 'category',
	            axisLine :{
	        		show:false
	        	},
	        	splitLine:{
	        		show:false
	            },
	            axisTick:{
        			show:false
	        	},
	        	axisLabel:{
//					clickable:true,
	        		textStyle:{
	        		align:'right',
					
	        	},
	        		margin:-10,
	        		
	        	},
	            boundaryGap : true,
	            data : lable
	        }
	    ],
	    xAxis : [
	        {
				 splitLine: {show: xAxisSplitLine,
					lineStyle:{
							 color: ['#EEE'],
							
						}},//不显示竖线
	            splitArea:{
					show:xAxissplitArea,
					areaStyle:{
							color: [
					        'rgba(250,250,250,0.1)',
					        'rgba(200,200,200,0.1)']
						}
				},
	        	axisLabel :{
        			show:false
	        	},
	        	axisTick:{
        			show:false
	        	},
	        	axisLine :{
        			show:false
        		},
	            type : 'value',
	            min:0, 
	            max:100
	        }
	    ],
	    series : datatemp
	};
	/**点击lable跳转到对应的模块报表
	var ecConfig = echarts.config.EVENT.CLICK;
	function eConsole(param) {
		window.location.href = "footfallWhole";
	    console.log(param);
	}
	myChart.on(ecConfig, eConsole);
	*/
	//改变窗口大小使图标自适应窗口显示
		window.onresize = function () {
			myChart.resize();
		}
		//加载折线图
		option.animation = false;
//		myChart.component.dataZoom.absoluteZoom(0,30);
		myChart.setOption(option);
//		myChart.clear();
		
//		myChart.setOption(option);
}

/**zb:指标; order:排序顺序;startDate:开始时间;endDate:结束时间*/
function getRankData() {
    var zbval = $("#zb").val();
    var order = $("#order").val();
    var startDate = $("#startDate").val();
    var endDate = $("#endDate").val();
    var siteKey = $("#siteKey").val();
    var zbArr = zbval.split(",");
	$.ajax({
		type: "GET",
		contentType: "application/json",
		dataType: 'json',
		url: "getIndexBigGraghData",
		data: {
			siteKey: siteKey,zbval : zbval,order : order,startDate : startDate,endDate : endDate,
		},
		async: true,
		success: function(ret) {
			//各指标最大值list
			var indexMaxValues = ret.indexMaxValues;
			//取出来的数据
			var result = ret.resultList;
			var html = "";
			var hrefurl = "";
			for (var i = 0; i < result.length;i++){
	               html += "<tr onclick=\"window.location='"+ hrefurl +"'\"><td width=\"5%\">&nbsp</td>";
	                html += '<td class="td1">' + i + '</td>';
	                html += '<td class="td2"><a href="index?siteKey=' + result[i].siteKey + '">' + result[i].siteName + '</a></td>';
	                html += '<td class="td3">';
	                var zbArr =  result[i].zbArr;
	                var indexValues = result[i].indexValues;
	                for (j = 0; j < zbArr.length; j++) {
	                    var kuan = indexValues[j]/indexMaxValues[j]*60;
	                    var num = indexValues[j];
	                    var wan="";
	                    num=format(num);
	                    html += '<div class="tiaomargin"><div class="fleft chartstiao' + zbArr[j] + '" style="width:' + kuan + '%;"></div><div class="fleft chartszi">' + num + ''+ wan +'' + danwei[zbArr[j]] + '</div><div class="cleardiv"></div></div>';
	                }
	                html += '<td width="5%" style="text-align:left"><a href="index?siteKey=' + result[i].siteKey + '"><img src="images/urlgo.png" style="height: 1.2em;" border="0"/></a></td></td>';
	                html += '</tr>';
			}
			 $("#htmlinner").html(html);
			
		},
		error : function(mm, a, b, c, d, e) {
				hideLoading();
				alert("服务器好像开小差了，刷新一下试试吧！");
			}
	})
}

